/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.haipv.gtkhoa501.screen;

import com.haipv.gtkhoa501.controller.Event;
import com.haipv.gtkhoa501.model.Signs;
import com.haipv.gtkhoa501.model.Var;
import com.sun.lwuit.Command;
import com.sun.lwuit.Container;
import com.sun.lwuit.Font;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.html.HTMLComponent;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import java.io.IOException;

/**
 *
 * @author PHANHAI
 * Giao diện hiển thị thông tin chi tiết biển báo giao thông.
 */
public class DetailSignScreen extends BaseScreen implements ActionListener{
    Command back = new Command(Var.back);
    String path="/images/signs/101.png";
    
    Signs sign;
    
    public void show(Signs _sign){
        this.sign = _sign;
        //Font font = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        Form form = new Form();
        
        Container con= new Container(new BoxLayout(BoxLayout.Y_AXIS));
        //con.setLayout(new BorderLayout());
        
        Container con1= new Container();
        Container con2= new Container();
        Container con3= new Container();
        
        Label  lab=null;
        try {
            lab= new Label(Image.createImage(Var.linkSigns+sign.getImg()+".png"));
            lab.getStyle().setAlignment(Label.CENTER);
            
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        con1.setLayout(new BorderLayout());
        con1.addComponent(BorderLayout.CENTER,lab);
        
        con.addComponent(con1);
        ///String txt=sign.getTitle().substring(8);
        TextArea text = new TextArea("số hiệu biển báo: "+sign.getImg()
                +"\ntên biển báo: "+sign.getTitle(),3,2);
        text.setEditable(false);
        con3.addComponent(text);
        HTMLComponent htmlComp = new HTMLComponent(null);
        htmlComp.setBodyText(sign.getContent(), "UTF-8");
        con3.addComponent(htmlComp);
        
        TextArea ta = new TextArea(sign.getContent(),10,10);
        ta.setEditable(false);
        //con3.addComponent(ta);
        con3.getStyle().setMargin(3, 3, 5, 5);
        con.addComponent(con3);
        con.setScrollableY(true);
        con.setScrollableX(false);
        
        form.setScrollable(false);
        form.addComponent(con);
        form.setBackCommand(back);
        form.addCommand(back);
        form.addCommandListener(this);
        form.show();
    }

    public void actionPerformed(ActionEvent ae) {
        if (ae.getCommand()==back){
            Event event = new Event();
                    event.setKey("TYPE", (sign.getType()) + "");
            controller.handleEvent(Event.SIGN_SELECT, event);
        }
    }
}
